/*    */ package com.chw.filter;
/*    */ 
/*    */ import com.chw.utils.AjaxUtil;
/*    */ import java.io.IOException;
/*    */ import javax.servlet.Filter;
/*    */ import javax.servlet.FilterChain;
/*    */ import javax.servlet.FilterConfig;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.ServletRequest;
/*    */ import javax.servlet.ServletResponse;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ 
/*    */ public class LoginFilter
/*    */   implements Filter
/*    */ {
/* 19 */   private String specialUrl = "";
/*    */ 
/*    */   public void destroy()
/*    */   {
/*    */   }
/*    */ 
/*    */   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
/*    */     throws IOException, ServletException
/*    */   {
/* 29 */     HttpServletRequest httpRequest = (HttpServletRequest)request;
/* 30 */     HttpServletResponse httpResponse = (HttpServletResponse)response;
/* 31 */     if (checkSpecialUrl(this.specialUrl, httpRequest)) {
/* 32 */       chain.doFilter(request, response);
/* 33 */       return;
/*    */     }
/* 35 */     HttpSession session = httpRequest.getSession();
/* 36 */     if (session.getAttribute("account") != null) {
/* 37 */       chain.doFilter(request, response);
/*    */     }
/*    */     else
/* 40 */       processRedirect(httpRequest, httpResponse, httpRequest.getContextPath() + "/public/page/login/login.html");
/*    */   }
/*    */ 
/*    */   public void init(FilterConfig arg0)
/*    */     throws ServletException
/*    */   {
/* 47 */     this.specialUrl = arg0.getInitParameter("specialUrl");
/*    */   }
/*    */ 
/*    */   private void processRedirect(HttpServletRequest request, HttpServletResponse response, String servletPath) {
/* 51 */     if (AjaxUtil.checkIsAjax(request))
/*    */     {
/* 53 */       response.setHeader("sessionstatus", "timeout");
/* 54 */       response.setHeader("redirectUri", servletPath);
/*    */     } else {
/*    */       try {
/* 57 */         response.sendRedirect(servletPath);
/*    */       } catch (IOException e) {
/* 59 */         e.printStackTrace();
/*    */       }
/*    */     }
/*    */   }
/*    */ 
/*    */   private boolean checkSpecialUrl(String specialUrl, HttpServletRequest request) {
/* 65 */     if ("".equals(specialUrl)) {
/* 66 */       return false;
/*    */     }
/* 68 */     String[] urlArray = specialUrl.split(";");
/* 69 */     for (String thisUrl : urlArray) {
/* 70 */       if (request.getRequestURL().indexOf(thisUrl) >= 0) {
/* 71 */         return true;
/*    */       }
/*    */     }
/* 74 */     return false;
/*    */   }
/*    */ }

/* Location:           E:\chenya\2017 4-21\com.chw\filter\
 * Qualified Name:     com.chw.filter.LoginFilter
 * JD-Core Version:    0.6.0
 */